package com.example.dell.boradcast;

import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;

import com.example.dell.basic.BasicAllActivity;


/**
 * 作者: 赵航
 * 创建时间: 2018/8/13 17:03
 * 描述:
 */
public class BoardCastUtils {

    private NetReceiver netWorkStateReceiver;
    private ScreamReceiver mScream;

    //监听网络的广播
    public void netWork(BasicAllActivity baseactivity) {
        if (netWorkStateReceiver==null) {
            netWorkStateReceiver = new NetReceiver(baseactivity);
            IntentFilter filter = new IntentFilter();
            filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
            baseactivity.registerReceiver(netWorkStateReceiver, filter);
        }
    }
    //注销网络广播
    public void unRegistNetWork(BasicAllActivity baseactivity){
        if (netWorkStateReceiver!=null) {
            baseactivity.unregisterReceiver(netWorkStateReceiver);
        }
    }
    //监听网络的广播
    public void sreamWork(BasicAllActivity baseactivity){
        if (mScream==null) {
            mScream = new ScreamReceiver(baseactivity);
            IntentFilter screamFilter = new IntentFilter();
            screamFilter.addAction(Intent.ACTION_SCREEN_OFF);
            screamFilter.addAction(Intent.ACTION_SCREEN_ON);
            baseactivity.registerReceiver(mScream, screamFilter);
        }
    }
    //注销网络广播监听
    public void unRegistScreamWork(BasicAllActivity baseactivity){
        if (mScream!=null) {
            baseactivity.unregisterReceiver(mScream);
        }
    }
}
